import { getAreaObj, uploadType } from '@/utils/util'

export const formConfig = {
	inline: false,
	showBtn: false,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '安装机构',
			prop: 'creditCode',
			propName: 'organizationName',
			type: 'remoteSelect',
			api: 'view_dpServiceOrgBase_page',
			filterKey: 'creditCode',
			filterLabel: 'organizationName',
			multiple: false,
			rules: [{ required: true, message: '请输入当前所属机构' }],
			span: 12,
			change: (item, form, value) => {
				form.provinceId = item.provinceId
				form.provinceName = item.provinceName
				form.cityId = item.cityId
				form.cityName = item.cityName
				form.areaId = item.areaId
				form.areaName = item.areaName
				form.streetId = item.streetId
				form.streetName = item.streetName
				form.communityId = item.communityId
				form.communicommunityNametyId = item.communityName
			},
		},
		{
			label: '摄像头编号',
			prop: 'videoNum',
			type: 'input',
			span: 12,
			rules: [{ required: true, message: '请输入摄像头编号' }],
		},
		{
			label: '摄像头类型',
			prop: 'videoType',
			propName: 'videoTypeLabel',
			type: 'remoteSelect',
			code: 'VIDEO_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			rules: [{ required: true, message: '请选择摄像头类型' }],
			span: 12,
		},

		{
			label: '摄像头位置',
			prop: 'videoLocation',
			type: 'input',
			span: 12,
		},
		{
			label: '播放地址',
			prop: 'videoUri',
			type: 'input',
			span: 12,
			rules: [{ required: true, message: '请输入播放地址' }],
		},
		{
			label: '摄像头账号',
			prop: 'videoUsername',
			type: 'input',
			span: 12,
		},
		{
			label: '摄像头账号密码',
			prop: 'videoPasswd',
			type: 'input',
			span: 12,
		},
		{
			label: 'ip地址',
			prop: 'videoIp',
			type: 'input',
			span: 12,
		},
		{
			label: '默认封面',
			tip: '',
			prop: 'posterImg',
			type: 'upload',
			labelPosition: 'top',
			showFileList: false,
			limit: 1,
			multiple: false,
			span: 24,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '摄像头编号', prop: 'videoNum' },
		{ label: '摄像头类型', prop: 'videoTypeLabel' },
		{ label: '账号', prop: 'videoUsername' },
		{ label: '密码', prop: 'videoPasswd' },
		{ label: '摄像头楼层', prop: 'videoFloor' },
		{ label: '摄像头位置', prop: 'videoLocation' },
		{
			label: '操作',
			prop: 'menu',
			width: 100,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_pbVideoSurveillance_page',
}
export const baseConfig = {
	pageName: '视频监控',
	dictcodes: ['VIDEO_TYPE'],
	rowKey: 'id',
	tipLabel: 'videoNum',
	api,
	auth: {
		...api,
	},
	paramsObj: {
		type: 2,
		source: 1,
	},
	menuBtn: [
		{
			icon: 'detail',
			label: '查看',
			type: 'primary',
			operate: 'detail',
			auth: api.index,
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '55%',
	},
	tableConfig,
	detailConfig: formConfig,
	operateFormate: async (form) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(form, '', 'get')
			resolve({
				...form,
				...areaObj,
				areas: areaObj.areaIds,
			})
		})
	},
	beforeOnLoadFormate: async (params) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(params.areas)
			resolve({
				...params,
				...areaObj,
				areas: undefined,
			})
		})
	},
}
